package com.ybf.api.mapper;

import com.ybf.api.entity.FileDetails;
import com.ybf.api.mapper.provider.FileDetailsProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ybf
 * @since 2024-09-26
 */
@Mapper
public interface FileDetailsMapper {

    @SelectProvider(type = FileDetailsProvider.class, method = "findAll")
    List<FileDetails> list(@Param("filedetails") FileDetails filedetails);

    @Delete("delete from file_list where id = #{id}")
    Integer delete(@Param("id") Integer id);

    @Select("select id, filename, filepath, filesize, filetype, hash, description, created_by, created_at, updated_at, status from file_list where id = #{id}")
    FileDetails info(@Param("id") Integer id);

    @Select("select id, filename, filepath, filesize, filetype, hash, description, created_by, created_at, updated_at, status from file_list where hash = #{hash}")
    FileDetails infoByHash(@Param("hash") String hash);

    @Insert("insert into file_list (filename, filepath, filesize, filetype, hash, description, created_by) values (#{filedetails.filename}, #{filedetails.filepath}, #{filedetails.filesize}, #{filedetails.filetype}, #{filedetails.hash}, #{filedetails.description}, #{filedetails.createdBy})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer add(@Param("filedetails") FileDetails filedetails);

    @Update("update file_list set status = '#{filedetails.status}' where id = #{filedetails.id}")
    Integer edit(@Param("filedetails") FileDetails filedetails);
}